package com.listener.work;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * <h3>springboot_rabbitmq_listener</h3>
 * <p>多个消费者绑定到一个队列,同一个消息只会被一个消费者处理</p>
 * 通过设置prefetch来控制消费着预取的消费数量
 *
 * @author gdw
 * @since 2024-07-22 15:41:23
 */
@Component
public class RabbitMaListenerWork {
    @RabbitListener(queues = "work.queue")
    public void work1(String message) throws InterruptedException {
        System.out.println("work1-------"+message);
        Thread.sleep(20);
    }
    @RabbitListener(queues = "work.queue")
    public void work2(String message) throws InterruptedException {
        System.out.println("work2-------"+message);
        Thread.sleep(200);
    }
}
